/**
 *
 */
package com.angel.mocks.data.generator.dataGenerator;

import java.util.Collection;

import org.apache.commons.lang.RandomStringUtils;

import com.angel.dao.generic.factory.DAOFactory;
import com.angel.dao.generic.interfaces.GenericDAO;
import com.angel.data.generator.interfaces.DataGenerator;
import com.angel.mocks.data.generator.daos.RoleDAO;
import com.angel.mocks.data.generator.daos.impl.UserHibernateDAO;
import com.angel.mocks.data.generator.domainObject.Role;
import com.angel.mocks.data.generator.domainObject.User;
import com.angel.mocks.data.generator.factory.TestHibernateDAOFactory;

/**
 * @author William
 *
 */
public class UserDataGenerator implements DataGenerator{

	private static final long serialVersionUID = -630713914137962975L;

	@SuppressWarnings("unchecked")
	public Class<? extends DataGenerator>[] getDependecesGenerators() {
		return (Class<? extends DataGenerator>[]) new Class<?>[]{UserTypeDataGenerator.class, RoleDataGenerator.class};
	}

	@SuppressWarnings("unchecked")
	public GenericDAO getGenericDAO() {
		return new UserHibernateDAO();
	}

	public void generateData(Collection<Object> dataCollection, DAOFactory daoFactory) {
		TestHibernateDAOFactory factory = (TestHibernateDAOFactory) daoFactory;
		RoleDAO roleDAO = factory.getRoleDAO();
		Role admin = roleDAO.findByName("Admin");
		User user = new User();
		user.setRole(admin);
		user.setAge(Integer.valueOf(RandomStringUtils.randomNumeric(5)));
		user.setName(RandomStringUtils.randomAlphabetic(10));
		user.setSurname(RandomStringUtils.randomAlphabetic(10));
		dataCollection.add(user);
	}


	public Class<? extends Object> getDataGeneratorClass() {
		return User.class;
	}

	public Class<?> thisDataGeneratorClass() {
		return this.getClass();
	}
}
